home *** CD-ROM | disk | FTP | other *** search
/ Family Forum 262 / SOMC Family Forum 262.iso / Xtras / ScriptOMatic Lite.Dxr / 00011.ls < prev    next >
Encoding:
Text File  |  1997-04-30  |  15.5 KB  |  410 lines

  1. global gScriptOMaticDefaultFormatTable, gScriptOMaticCurrentFormatTable, gScriptOMaticMasterColorTable, gScriptOMaticObject, gScriptOMaticVersion, gScriptOMaticPreview, gScriptOMaticZoomOut, gScriptOMaticDebug, gScriptOMaticDemo, gScriptOMaticWindow, gScriptOMaticElementDelimiters, gScriptOMaticUsageCount
  2.  
  3. on startMovie
  4.   set gScriptOMaticDemo to 1
  5.   set gScriptOMaticZoomOut to 1
  6.   set gScriptOMaticDebug to 0
  7.   set gScriptOMaticWindow to the activeWindow
  8.   if the platform contains "Mac" then
  9.     case gScriptOMaticDemo of
  10.       1:
  11.         set the title of gScriptOMaticWindow to "ScriptOMaticΓäó Lite XtraΓäó"
  12.       0:
  13.         set the title of gScriptOMaticWindow to "ScriptOMaticΓäó XtraΓäó"
  14.     end case
  15.     set the windowType of gScriptOMaticWindow to 52
  16.   else
  17.     case gScriptOMaticDemo of
  18.       1:
  19.         set the title of gScriptOMaticWindow to "ScriptOMatic(tm) Lite Xtra(tm)"
  20.       0:
  21.         set the title of gScriptOMaticWindow to "ScriptOMatic(tm) Xtra(tm)"
  22.     end case
  23.     set the windowType of gScriptOMaticWindow to 4
  24.   end if
  25.   set gScriptOMaticVersion to "1.0"
  26.   set gScriptOMaticUsageCount to 0
  27.   tell the stage
  28.     set theMovie to the movie
  29.   end tell
  30.   set gScriptOMaticPreview to 1
  31.   if gScriptOMaticDemo then
  32.     checkForBetaExpiration()
  33.   end if
  34.   set gScriptOMaticElementDelimiters to field "delimiters"
  35.   set gScriptOMaticDefaultFormatTable to [#handlerDeclarationsFormat: [#id: 1, #activate: 1, #Color: "Black", #style: "Bold", #face: "Monospaced", #size: "9"], #globalDeclarationsFormat: [#id: 2, #activate: 1, #Color: "Red", #style: "Bold", #face: "Monospaced", #size: "9"], #propertyDeclarationsFormat: [#id: 3, #activate: 1, #Color: "Blue", #style: "Bold", #face: "Monospaced", #size: "9"], #localDeclarationsFormat: [#id: 4, #activate: 1, #Color: "Brown", #style: "Bold", #face: "Monospaced", #size: "9"], #handlerNamesFormat: [#id: 5, #activate: 1, #Color: "Black", #style: "Underline", #face: "Monospaced", #size: "9"], #globalVariablesFormat: [#id: 6, #activate: 1, #Color: "Red", #style: "Plain", #face: "Monospaced", #size: "9"], #propertyVariablesFormat: [#id: 7, #activate: 1, #Color: "Blue", #style: "Plain", #face: "Monospaced", #size: "9"], #localVariablesFormat: [#id: 8, #activate: 1, #Color: "Brown", #style: "Underline", #face: "Monospaced", #size: "9"], #commentsFormat: [#id: 9, #activate: 1, #Color: "Green", #style: "Italic", #face: "Proportional", #size: "12"], #keywordsFormat: [#id: 10, #activate: 0, #Color: "Green", #style: "Bold", #face: "Monospaced", #size: "9"]]
  36.   if not gScriptOMaticDemo then
  37.     put "Monospaced" & RETURN & "Proportional" & RETURN & "Custom Font[" & GetInstalledFonts() & "]" into field "TextFace"
  38.   else
  39.     put "Monospaced" & RETURN & "Proportional" & RETURN & "Custom Font[Not Available in Lite Version]" into field "TextFace"
  40.   end if
  41.   set gScriptOMaticMasterColorTable to [#BROWN: [26214, 13107, 0], #PURPLE: [39321, 0, 26214], #red: [60947, 0, 0], #blue: [0, 0, 60947], #green: [0, 30801, 0], #BLACK: [0, 0, 0]]
  42.   sort(gScriptOMaticMasterColorTable)
  43.   set totalXtras to the number of xtras
  44.   set xtraLoaded to 0
  45.   repeat with theXtraNum = 1 to totalXtras
  46.     if the name of xtra(theXtraNum) = "ScriptColor" then
  47.       set xtraLoaded to 1
  48.     end if
  49.   end repeat
  50.   if xtraLoaded = 1 then
  51.     set traceState to the trace
  52.     set the trace to 0
  53.     Register(xtra("ScriptColor"), scolSerial())
  54.     set the trace to traceState
  55.     resetFormats()
  56.   else
  57.     alert("The ScriptColor Xtra component was not installed.  Please place it into your Xtras folder, relaunch Director and try again.")
  58.     closeScriptOMatic()
  59.   end if
  60. end
  61.  
  62. on closeWindow
  63.   closeScriptOMatic()
  64. end
  65.  
  66. on scolSerial
  67.   return "SCOL" & string(9999 - 7547) & "-" & string(9999 - 2776) & "-" & string(9999 - 6568) & "-" & string(9999 - 6507)
  68. end
  69.  
  70. on closeScriptOMatic
  71.   alert("Thanks for using" && the title of gScriptOMaticWindow && "!  Email your feature ideas to <ideas@gmatter.com>...")
  72.   set gScriptOMaticDefaultFormatTable to VOID
  73.   set gScriptOMaticCurrentFormatTable to VOID
  74.   set gScriptOMaticMasterColorTable to VOID
  75.   set gScriptOMaticObject to VOID
  76.   set gScriptOMaticDemo to VOID
  77.   set gScriptOMaticUsageCount to VOID
  78.   set gScriptOMaticVersion to VOID
  79.   set gScriptOMaticPreview to VOID
  80.   set gScriptOMaticZoomOut to VOID
  81.   set gScriptOMaticDebug to VOID
  82.   set gScriptOMaticElementDelimiters to VOID
  83.   set windowString to string(gScriptOMaticWindow)
  84.   set startPos to offset(QUOTE, string(windowString)) + 1
  85.   set windowNameString to char startPos to length(windowString) - 2 of windowString
  86.   if windowPresent(windowNameString) then
  87.     forget(gScriptOMaticWindow)
  88.     set gScriptOMaticWindow to VOID
  89.   else
  90.     set gScriptOMaticWindow to VOID
  91.     halt()
  92.   end if
  93. end
  94.  
  95. on checkForBetaExpiration
  96. end
  97.  
  98. on stopMovie
  99.   closeScriptOMatic()
  100. end
  101.  
  102. on displayDemoOverAlert
  103.   alert(the title of gScriptOMaticWindow && "only allows a total of 20 scripts to be formatted per session." & RETURN & "Call g/matter, inc. at +1-415-243-0394 or email <sales@gmatter.com> to purchase a full feature version of ScriptOMatic Xtra!")
  104.   closeScriptOMatic()
  105. end
  106.  
  107. on keyDown
  108.   if the key = RETURN then
  109.     formatCurrentScript()
  110.   end if
  111. end
  112.  
  113. on resizeSOMWindow windowLayoutSymbol
  114.   set currentRect to the rect of gScriptOMaticWindow
  115.   set wLeft to the left of currentRect
  116.   set wTop to the top of currentRect
  117.   case windowLayoutSymbol of
  118.     #outprev:
  119.       set newRect to rect(wLeft, wTop, wLeft + 576, wTop + 340)
  120.       go("outprev")
  121.     #outnoprev:
  122.       set newRect to rect(wLeft, wTop, wLeft + 576, wTop + 210)
  123.       go("outnoprev")
  124.     #in:
  125.       set newRect to rect(wLeft, wTop, wLeft + 288, wTop + 210)
  126.       go("in")
  127.   end case
  128.   set the rect of gScriptOMaticWindow to newRect
  129. end
  130.  
  131. on zoomWindow
  132.   set gScriptOMaticZoomOut to not gScriptOMaticZoomOut
  133.   case gScriptOMaticZoomOut of
  134.     1:
  135.       case gScriptOMaticPreview of
  136.         1:
  137.           resizeSOMWindow(#outprev)
  138.         0:
  139.           resizeSOMWindow(#outnoprev)
  140.       end case
  141.     0:
  142.       resizeSOMWindow(#in)
  143.   end case
  144. end
  145.  
  146. on resetFormats
  147.   set gScriptOMaticCurrentFormatTable to duplicate(gScriptOMaticDefaultFormatTable)
  148.   set totalElements to count(gScriptOMaticDefaultFormatTable)
  149.   repeat with elementIndex = 1 to 9
  150.     set elementSymbol to getPropAt(gScriptOMaticDefaultFormatTable, elementIndex)
  151.     set elementData to getaProp(gScriptOMaticDefaultFormatTable, elementSymbol)
  152.     set the hilite of member ("activate" & string(the id of elementData)) to the activate of elementData
  153.     setDisplayText(member ("color" & string(the id of elementData)), string(the Color of elementData))
  154.     setFont(member ("color" & string(the id of elementData)), popMenuFont())
  155.     setFontSize(member ("color" & string(the id of elementData)), popMenuFontSize())
  156.     setDisplayText(member ("style" & string(the id of elementData)), string(the style of elementData))
  157.     setFont(member ("style" & string(the id of elementData)), popMenuFont())
  158.     setFontSize(member ("style" & string(the id of elementData)), popMenuFontSize())
  159.     setMenuField(member ("face" & string(the id of elementData)), member "TextFace")
  160.     setDisplayText(member ("face" & string(the id of elementData)), string(the face of elementData))
  161.     setFont(member ("face" & string(the id of elementData)), popMenuFont())
  162.     setFontSize(member ("face" & string(the id of elementData)), popMenuFontSize())
  163.     setDisplayText(member ("size" & string(the id of elementData)), string(the size of elementData))
  164.     setFont(member ("size" & string(the id of elementData)), popMenuFont())
  165.     setFontSize(member ("size" & string(the id of elementData)), popMenuFontSize())
  166.   end repeat
  167. end
  168.  
  169. on popMenuFontSize
  170.   if the platform starts "M" then
  171.     return 9
  172.   else
  173.     return 12
  174.   end if
  175. end
  176.  
  177. on popMenuFont
  178.   if the platform starts "M" then
  179.     return "Geneva"
  180.   else
  181.     return "Arial"
  182.   end if
  183. end
  184.  
  185. on formatCurrentScript
  186.   if gScriptOMaticDemo and (gScriptOMaticUsageCount >= 20) then
  187.     displayDemoOverAlert()
  188.   else
  189.     cursor(4)
  190.     if gScriptOMaticDebug then
  191.       set now to the ticks
  192.     end if
  193.     set handlerNamelist to findAllHandlers()
  194.     tell the stage
  195.       set currentCastLib to the activeCastLib
  196.       set selectionList to the selection of castLib currentCastLib
  197.     end tell
  198.     if count(selectionList) > 0 then
  199.       set currentMember to getAt(getAt(selectionList, 1), 1)
  200.       tell the stage
  201.         set memberType to the type of member currentMember of castLib currentCastLib
  202.       end tell
  203.       if memberType <> #empty then
  204.         tell the stage
  205.           set scriptText to the scriptText of member currentMember of castLib currentCastLib
  206.         end tell
  207.         if (scriptText <> EMPTY) and (scriptText <> RETURN) and (scriptText <> " ") then
  208.           set gScriptOMaticObject to new(script "ScriptFormatter", currentMember, currentCastLib, scriptText, handlerNamelist)
  209.           parseScript(gScriptOMaticObject)
  210.           formatScript(gScriptOMaticObject)
  211.           if gScriptOMaticDemo then
  212.             set gScriptOMaticUsageCount to gScriptOMaticUsageCount + 1
  213.           end if
  214.           cursor(-1)
  215.         else
  216.           alert("The current castmember is either not a script or does not have a cast script attached.")
  217.         end if
  218.         if gScriptOMaticDebug then
  219.           set endTicks to the ticks - now
  220.           put "Formatted the current script in", endTicks, "ticks"
  221.         end if
  222.       else
  223.         alert("The currently selected castmember in the stage movie is empty.")
  224.       end if
  225.     else
  226.       alert("There are no castmembers selected in the stage movie.")
  227.     end if
  228.     cursor(-1)
  229.   end if
  230. end
  231.  
  232. on formatAllScripts
  233.   if gScriptOMaticDemo and (gScriptOMaticUsageCount >= 20) then
  234.     displayDemoOverAlert()
  235.   else
  236.     cursor(4)
  237.     if gScriptOMaticDebug then
  238.       set now to the ticks
  239.     end if
  240.     set handlerNamelist to findAllHandlers()
  241.     set totalFormatted to 0
  242.     tell the stage
  243.       set totalCastLibs to the number of castLibs
  244.     end tell
  245.     repeat with theCastLib = 1 to totalCastLibs
  246.       tell the stage
  247.         set totalMembers to the number of castMembers of castLib theCastLib
  248.       end tell
  249.       repeat with theMember = 1 to totalMembers
  250.         tell the stage
  251.           set scriptText to the scriptText of member theMember of castLib theCastLib
  252.         end tell
  253.         if (scriptText <> EMPTY) and (scriptText <> RETURN) and (scriptText <> " ") then
  254.           set totalFormatted to totalFormatted + 1
  255.           set gScriptOMaticObject to new(script "ScriptFormatter", theMember, theCastLib, scriptText, handlerNamelist)
  256.           parseScript(gScriptOMaticObject)
  257.           formatScript(gScriptOMaticObject)
  258.           if gScriptOMaticDebug then
  259.             set endTicks to the ticks - now
  260.           end if
  261.           if gScriptOMaticDemo and (totalFormatted >= 5) then
  262.             alert(the title of gScriptOMaticWindow && "only allows formatting of the first 5 scripts found." & RETURN & "Call g/matter, inc. at +1-415-243-0394 or email <sales@gmatter.com> to purchase a full feature version of ScriptOMatic Xtra!")
  263.             set theCastLib to totalCastLibs + 1
  264.             exit repeat
  265.           end if
  266.         end if
  267.       end repeat
  268.     end repeat
  269.     cursor(-1)
  270.     if gScriptOMaticDemo then
  271.       set gScriptOMaticUsageCount to gScriptOMaticUsageCount + 1
  272.     end if
  273.     if totalFormatted = 0 then
  274.       alert("Sorry, but no scripts were found in your stage movie.")
  275.     else
  276.       if gScriptOMaticDebug then
  277.         put "formatted", totalFormatted, "scripts in", endTicks, "ticks"
  278.       end if
  279.       if gScriptOMaticDebug then
  280.         put "average time was", endTicks / float(totalFormatted), "ticks"
  281.       end if
  282.     end if
  283.   end if
  284. end
  285.  
  286. on elements string, elementNum
  287.   set totalChars to length(string)
  288.   set elementList to []
  289.   set element to EMPTY
  290.   repeat with theChar = 1 to totalChars
  291.     set aChar to char theChar of string
  292.     if gScriptOMaticElementDelimiters contains aChar then
  293.       if element <> EMPTY then
  294.         add(elementList, element)
  295.         set element to EMPTY
  296.       end if
  297.       next repeat
  298.     end if
  299.     put aChar after element
  300.   end repeat
  301.   if element <> EMPTY then
  302.     add(elementList, element)
  303.   end if
  304.   if not voidp(elementNum) then
  305.     return getAt(elementList, elementNum)
  306.   else
  307.     return elementList
  308.   end if
  309. end
  310.  
  311. on elementsData string, elementNum
  312.   set totalChars to length(string)
  313.   set elementList to [:]
  314.   set element to EMPTY
  315.   set elementLoc to 1
  316.   set waitingForNewElement to 1
  317.   repeat with theChar = 1 to totalChars
  318.     set aChar to char theChar of string
  319.     if gScriptOMaticElementDelimiters contains aChar then
  320.       if element <> EMPTY then
  321.         addProp(elementList, element, elementLoc)
  322.         set element to EMPTY
  323.         set waitingForNewElement to 1
  324.       end if
  325.       next repeat
  326.     end if
  327.     if waitingForNewElement then
  328.       set waitingForNewElement to 0
  329.       set elementLoc to theChar
  330.     end if
  331.     put aChar after element
  332.   end repeat
  333.   if element <> EMPTY then
  334.     addProp(elementList, element, elementLoc)
  335.   end if
  336.   if not voidp(elementNum) then
  337.     return getAt(elementList, elementNum)
  338.   else
  339.     return elementList
  340.   end if
  341. end
  342.  
  343. on eTest
  344.   set testString to "tell the stage to put (the scriptText of member currentMember of castLib the activeCastlib <> EMPTY) into scriptAvailable"
  345.   startTimer()
  346.   repeat with X = 1 to 200
  347.     set r to elementsData(testString)
  348.   end repeat
  349.   put the timer
  350. end
  351.  
  352. on displayAboutBox
  353.   if the shiftDown then
  354.     alert("Special thanks to Karyn Schussler, Joshua Bryan Schussler (my *other* new product), Jonathan Grayson, Mike Edmunds, Anders Wallgren, Diana Wynne, John C. Ware, Leesa Lee, Jim Corbett, Carrie Myers, Doug Wyrick, Mike Seery, Bill Schulze and Shan Franklin.")
  355.   else
  356.     if the optionDown then
  357.       alert("This is only a demo.  Were this an actual product, you would see flying chrome logos and piecharts and hear dancing boys and trombones.  But this is only a demo.")
  358.     else
  359.       alert(the title of gScriptOMaticWindow && "version" && gScriptOMaticVersion & RETURN & "Copyright ┬⌐ 1997 by g/matter, inc." & RETURN & "All Rights Reserved." & RETURN & RETURN & "ScriptColor Xtra component engineered by Glenn Picher, Dirigo Multimedia." & RETURN & the title of gScriptOMaticWindow && "designed and engineered by Terry R. Schussler.")
  360.     end if
  361.   end if
  362. end
  363.  
  364. on findAllHandlers
  365.   if gScriptOMaticDebug then
  366.     set now to the ticks
  367.   end if
  368.   set handlerNamelist to []
  369.   sort(handlerNamelist)
  370.   tell the stage
  371.     set totalCastLibs to the number of castLibs
  372.   end tell
  373.   repeat with theCastLib = 1 to totalCastLibs
  374.     tell the stage
  375.       set totalMembers to the number of castMembers of castLib theCastLib
  376.     end tell
  377.     repeat with theMember = 1 to totalMembers
  378.       tell the stage
  379.         set memberType to the type of member theMember of castLib theCastLib
  380.       end tell
  381.       if memberType = #script then
  382.         tell the stage
  383.           set memberScriptType to the scriptType of member theMember of castLib theCastLib
  384.         end tell
  385.         if memberScriptType = #movie then
  386.           tell the stage
  387.             set scriptText to the scriptText of member theMember of castLib theCastLib
  388.           end tell
  389.           if scriptText <> EMPTY then
  390.             set totalLines to the number of lines in scriptText
  391.             repeat with theLine = 1 to totalLines
  392.               if word 1 of line 1 of scriptText = "on" then
  393.                 add(handlerNamelist, symbol(word 2 of line 1 of scriptText))
  394.               end if
  395.               delete line 1 of scriptText
  396.             end repeat
  397.           end if
  398.         end if
  399.       end if
  400.     end repeat
  401.   end repeat
  402.   if gScriptOMaticDebug then
  403.     set endTicks to the ticks - now
  404.   end if
  405.   if gScriptOMaticDebug then
  406.     put "Found all the handlers in", endTicks, "ticks"
  407.   end if
  408.   return handlerNamelist
  409. end
  410.